package com.tansun.easycare.rule.common.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tansun.easycare.rule.common.model.SelectModelVo;
import com.tansun.easycare.rule.common.service.RuleCommService;
import com.tansun.easycare.rule.exception.BizException;
import com.tansun.easycare.rule.rulemange.dao.RuleManageDao;
import com.tansun.easycare.rule.ruleversion.dao.RuleVersioninfoDao;
import com.tansun.easycare.rule.ruleversion.entity.RuleVersioninfo;

@Service("ruleCommService")
public class RuleCommServiceImpl implements RuleCommService {

    @Autowired
    private RuleManageDao ruleManageDao;

    @Autowired
    private RuleVersioninfoDao ruleVersioninfoDao;

    @Override
    public List<SelectModelVo> findSelectModelList(String projectCode, String modelType) throws BizException {
        Map<String, Object> map = new HashMap();
        map.put("projectCode", projectCode);
        map.put("modelType", modelType);
        map.put("status", "2");
        return this.ruleManageDao.findSelectModelList(map);

    }

    @Override
    public List<SelectModelVo> findSelectVersionList(String projectCode, String code) throws BizException {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("projectCode", projectCode);
        map.put("code", code);
        List<RuleVersioninfo> list = this.ruleVersioninfoDao.findVersionList(map);
        List<SelectModelVo> result = new ArrayList();
        for (RuleVersioninfo ruleVers : list) {
            if (!"v0.00".equals(ruleVers.getVersion())) {
                result.add(new SelectModelVo(ruleVers.getVersion(), ruleVers.getVersion()));
            }
        }
        return result;
    }


    @Override
    public List<SelectModelVo> findSelectPublishVersionList(String projectCode, String code) throws BizException {
        RuleVersioninfo versioninfo = new RuleVersioninfo();
        versioninfo.setProjectCode(projectCode);
        versioninfo.setModelCode(code);
        List<RuleVersioninfo> list = this.ruleVersioninfoDao.findPublishVersionList(versioninfo);
        List<SelectModelVo> result = new ArrayList();
        for (RuleVersioninfo ruleVers : list) {
            if (!"v0.00".equals(ruleVers.getVersion())) {
                result.add(new SelectModelVo(ruleVers.getVersion(), ruleVers.getVersion()));
            }
        }
        return result;
    }

	@Override
	public List<SelectModelVo> findSelectModelFunctionParamList(String projectCode, String modelType)
			throws BizException {
		Map<String, Object> map = new HashMap();
        map.put("projectCode", projectCode);
        map.put("modelType", modelType);
        //map.put("status", "2");
//        List<RuleDataparams> pList = this.decisionTreeService.findFunctionParam(map);
        return this.ruleManageDao.findSelectModelFunctionParamList(map);
	}


}
